﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KPIS.GERP.GBMS.IBLL;
using KPIS.GERP.GBMS.BLL;
using KPIS.GERP.GBMS.MODEL;
//using KPIS.Utils;
using Telerik.Web.UI;

namespace KPIS.GERP.GBMS.APP_UI
{
    public partial class BGM_System_Approve : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CreateNewSequence(Convert.ToInt16(lbCountRow.Text));
        }

        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            lbCountRow.Text = (Convert.ToInt16(lbCountRow.Text) + 1).ToString();
            CreateNewSequence(1);
        }

        protected void btnDel_Click(object sender, ImageClickEventArgs e)
        {
            if (Convert.ToInt16(lbCountRow.Text) > 0)
            {
                tb.Rows.RemoveAt(tb.Rows.Count - 1);
                lbCountRow.Text = (Convert.ToInt16(lbCountRow.Text) - 1).ToString();
            }
            else
            {
                lbCountRow.Text = "0";
            }
        }

        # region Create New Sequence
        private void CreateNewSequence(int nCount)
        {
            if (nCount > 0)
            {
                
                for (int i = 0; i < nCount; i++)
                {
                    TableRow tr = new TableRow();

                    TableCell tc1 = new TableCell();
                    TableCell tc2 = new TableCell();
                    TableCell tc3 = new TableCell();

                    RadComboBox cb1 = new RadComboBox();
                    RadComboBox cb2 = new RadComboBox();

                    ImageButton del = new ImageButton();

                    // ------ Set ImageButton Property ----------

                    del.ImageUrl = "../Image/Grid/Cancel.gif";
                    del.Click += new ImageClickEventHandler(this.btnDel_Click);

                    // ------ Add VALUES and Text To ComboBox ----

                    for (int j = 0; j < tb.Rows.Count; j++)
                    {
                        cb1.Items.Add(new RadComboBoxItem((j + 1).ToString(), (j + 1).ToString()));
                    }

                    // ------ Set ComboBox Properties -----

                    cb1.Width = 50;
                    cb2.Width = 350;

                    cb1.ID = "cbSeq" + (tb.Rows.Count).ToString();
                    cb2.ID = "cbExecPos" + (tb.Rows.Count).ToString();

                    cb1.SelectedIndex = cb1.Items.Count - 1;

                    // ------ Set Cells Style ------

                    tc1.Height = 20;
                    tc2.Height = 20;
                    tc3.Height = 20;
                    tc2.HorizontalAlign = HorizontalAlign.Left;

                    // ------ Add ComboBox to Cells -----

                    tc1.Controls.Add(cb1);
                    tc2.Controls.Add(cb2);
                    tc3.Controls.Add(del);

                    // ------ Add Cells To Rows

                    tr.Cells.AddAt(0, tc1);
                    tr.Cells.AddAt(1, tc2);
                    tr.Cells.AddAt(2, tc3);

                    // ------ Add Row To Table

                    tb.Rows.Add(tr);
                }
            }
            else
                lbCountRow.Text = "0";
        }
        # endregion
    }
}
